<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Exercise 5.1d: Sensitivity analysis for a simple QCQP</title>
<link rel="canonical" href="/Users/mcgrant/Repos/CVX/examples/cvxbook/Ch05_duality/html/ex_5_1.html">
<link rel="stylesheet" href="../../../examples.css" type="text/css">
</head>
<body>
<div id="header">
<h1>Exercise 5.1d: Sensitivity analysis for a simple QCQP</h1>
Jump to:&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#source">Source code</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#output">Text output</a>
&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#plots">Plots</a>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../../index.html">Library index</a>
</div>
<div id="content">
<a id="source"></a>
<pre class="codeinput">
<span class="comment">% Boyd &amp; Vandenberghe, "Convex Optimization"</span>
<span class="comment">% Jo&euml;lle Skaf - 08/29/05</span>
<span class="comment">% (a figure is generated)</span>
<span class="comment">%</span>
<span class="comment">% Let p_star(u) denote the optimal value of:</span>
<span class="comment">%           minimize    x^2 + 1</span>
<span class="comment">%               s.t.    (x-2)(x-2)&lt;=u</span>
<span class="comment">% Finds p_star(u) and plots it versus u.</span>

fprintf(1,<span class="string">'Computing p_star(u)...\n '</span>);

u = linspace(-0.9,10,50);
p_star = zeros(1,length(u));
<span class="keyword">for</span> i = 1:length(u)
    disp([<span class="string">'for u = '</span> num2str(u(i))]);
    <span class="comment">% perturbed problem</span>
    cvx_begin <span class="string">quiet</span>
        variable <span class="string">x(1)</span>
        minimize ( quad_form(x,1) + 1 )
        quad_form(x,1) - 6*x + 8 &lt;= u(i);
    cvx_end
    <span class="comment">% optimal value</span>
    p_star(i) = cvx_optval;
<span class="keyword">end</span>

fprintf(1,<span class="string">'Done! \n'</span>);

<span class="comment">% Plots</span>
plot(u,p_star)
axis([-2 10 -2 10])
xlabel(<span class="string">'u'</span>);
ylabel(<span class="string">'p^*(u)'</span>)
title(<span class="string">'Sensitivity analysis: p^*(u) vs u'</span>);
</pre>
<a id="output"></a>
<pre class="codeoutput">
Computing p_star(u)...
 for u = -0.9
for u = -0.67755
for u = -0.4551
for u = -0.23265
for u = -0.010204
for u = 0.21224
for u = 0.43469
for u = 0.65714
for u = 0.87959
for u = 1.102
for u = 1.3245
for u = 1.5469
for u = 1.7694
for u = 1.9918
for u = 2.2143
for u = 2.4367
for u = 2.6592
for u = 2.8816
for u = 3.1041
for u = 3.3265
for u = 3.549
for u = 3.7714
for u = 3.9939
for u = 4.2163
for u = 4.4388
for u = 4.6612
for u = 4.8837
for u = 5.1061
for u = 5.3286
for u = 5.551
for u = 5.7735
for u = 5.9959
for u = 6.2184
for u = 6.4408
for u = 6.6633
for u = 6.8857
for u = 7.1082
for u = 7.3306
for u = 7.5531
for u = 7.7755
for u = 7.998
for u = 8.2204
for u = 8.4429
for u = 8.6653
for u = 8.8878
for u = 9.1102
for u = 9.3327
for u = 9.5551
for u = 9.7776
for u = 10
Done! 
</pre>
<a id="plots"></a>
<div id="plotoutput">
<img src="ex_5_1__01.png" alt=""> 
</div>
</div>
</body>
</html>